package componentnameisunique;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import componentnameisunique.ComponentNameIsUniqueMatch;
import componentnameisunique.ComponentNameIsUniqueMatcherFactory;
import componentnameisunique.ComponentNameIsUniqueMatcher;

public class ComponentNameIsUniqueConstraint extends Constraint<ComponentNameIsUniqueMatch> {

	private ComponentNameIsUniqueMatcherFactory matcherFactory;

	public ComponentNameIsUniqueConstraint() {
		matcherFactory = new ComponentNameIsUniqueMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "There are more than one components with name $component.name$. Component names should be unique!";
	}

	@Override
	public EObject getLocationObject(ComponentNameIsUniqueMatch signature) {
		Object location = signature.get("component");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ComponentNameIsUniqueMatch, ComponentNameIsUniqueMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
